<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>${metadata.alias!}${word?has_content?then(' - '+word,'')}</title>
    <meta name="keywords" content="<#list getKeywords(word) as a>${a}<#sep>,</#list>"/>
    <meta name="description" content="${site.name} - Search"/>
</head>
<body>
    <header data-diy="config" data-diy-id="siteAttribute">
        <form method="get">
            <input type="text" name="word" value="${word!}"/>
            <input type="submit" value="Search"/>
        </form>
    </header>
    <nav data-diy="category">
        <a href="${site.dynamicPath}">Home</a>
<@cms.categoryList>
    <#list page.list as a>
        <a href="${a.url!}" target="_blank" data-diy-item="${a.id}">${a.name}</a>
    </#list>
</@cms.categoryList>
    </nav>
    <main>
<#macro merge name value><#if !.vars[name]??><@"<#assign ${name}=''>"?interpret /></#if><#if value?has_content><@"<#assign ${name}=${name}+'${value},'>"?interpret /></#if></#macro>
<@cms.search word=word tagId=tagId highlight=true pageIndex=pageIndex pageSize=10>
    <#if page.totalCount gt 0>
        <h1>Results</h1>
    <#list page.list as a>
        <@merge 'categoryIds' a.categoryId!/>
    </#list>
    <@cms.category ids=categoryIds><#assign categoryMap=map/></@cms.category>
        <div>
    <#list page.list as a>
            <article data-diy-item="${a.id}">
                <h3>[<a href="${(categoryMap[a.categoryId?string].url)!}" target="_blank">${(categoryMap[a.categoryId?string].name)!}</a>]<a href="<#if a.onlyUrl>${site.dynamicPath}content/redirect?id=${a.id}<#else>${a.url!}</#if>" target="_blank">${a.title?no_esc}</a></h3>
                <p>
                    <#if a.cover?has_content><img src="${a.cover}" alt="${a.title}"/></#if>
                    ${(a.description?no_esc)!}
                </p>
            </article>
    </#list>
        </div>
        <div>
            <#if !page.firstPage>
                <a href="?word=${word!}&tagId=${tagId!}&pageIndex=${page.prePage}">Previous page</a>
            <#else>
                <span>Previous page</span>
            </#if>
            <#assign
                start=1
                end=page.totalPage
            />
            <#if (page.pageIndex-5) gt start>
                <#assign start=page.pageIndex-4/>
            </#if>
            <#if (page.pageIndex+5) lt end>
                <#assign end=page.pageIndex+4/>
            </#if>
            <#if start gt 1>
                <a href="?word=${word!}&tagId=${tagId!}">1</a> ...
            </#if>
            <#list start..end as n>
                <#if n=page.pageIndex>
                    ${n}
                <#else>
                    <a href="?word=${word!}&tagId=${tagId!}&pageIndex=${n}">${n}</a>
                </#if>
            </#list>
            <#if end lt page.totalPage>
                ... <a href="?word=${word!}&tagId=${tagId!}&pageIndex=${page.totalPage}">${page.totalPage}</a>
            </#if>
            <#if !page.lastPage>
                <a href="?word=${word!}&tagId=${tagId!}&pageIndex=${page.nextPage}">Next page</a>
            <#else>
                <span>Next page</span>
            </#if>
        </div>
    </#if>
</@cms.search>
        <aside>
            <h3>Popular content</h3>
            <ul data-diy="content">
<@cms.contentList orderField='clicks' pageSize=10>
    <#list page.list as a>
                <li data-diy-item="${a.id}"><a href="<#if a.onlyUrl>${site.dynamicPath}content/redirect?id=${a.id}<#else>${a.url!}</#if>" target="_blank">${a.title}</a><span>${a.clicks}</span></li>
    </#list>
</@cms.contentList>
            </ul>
        </aside>
    </main>
    <footer>
        Copyright &copy; ${.now?string('yyyy')}
    </footer>
    <script>
    var templatePath='${.current_template_name?keep_after('/')}';
    </script>
    <script src="${site.dynamicPath}resource/js/cms.support.js"></script>
    <script>
        var ca = cmsAnalytics();
        var url='${site.dynamicPath}api/visit/record';
        if("string" ==typeof itemString){
            url=url+"?"+itemString;
        }
        ca.setDomain('${site.sitePath?keep_after('//')?keep_before('/')?keep_before(':')}');
        ca.setPath('/');
        ca.report(url);
    </script>
</body>
</html>